<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Nginx日志配置完全指南 | 技术小馆</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4, h5, h6 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .code-block {
            background-color: #2d2d2d;
            color: #f8f8f2;
            border-radius: 8px;
            position: relative;
        }
        .code-block pre {
            margin: 0;
            padding: 1.5rem;
            overflow-x: auto;
        }
        .code-block .copy-btn {
            position: absolute;
            top: 0.5rem;
            right: 0.5rem;
            background-color: rgba(255,255,255,0.1);
            border: none;
            color: #f8f8f2;
            padding: 0.25rem 0.5rem;
            border-radius: 4px;
            cursor: pointer;
            transition: all 0.2s;
        }
        .code-block .copy-btn:hover {
            background-color: rgba(255,255,255,0.2);
        }
        .card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
            border-radius: 12px;
            overflow: hidden;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .highlight-box {
            border-left: 4px solid #6e8efb;
            background-color: #f8f9fa;
            padding: 1.5rem;
            border-radius: 0 8px 8px 0;
        }
        .nav-link {
            position: relative;
        }
        .nav-link:after {
            content: '';
            position: absolute;
            width: 0;
            height: 2px;
            bottom: 0;
            left: 0;
            background-color: #6e8efb;
            transition: width 0.3s ease;
        }
        .nav-link:hover:after {
            width: 100%;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:py-28">
        <div class="container mx-auto max-w-5xl text-center">
            <div class="flex justify-center mb-6">
                <div class="bg-white bg-opacity-10 rounded-full px-4 py-1 flex items-center">
                    <i class="fas fa-server mr-2"></i>
                    <span>服务器运维</span>
                </div>
            </div>
            <h1 class="text-4xl md:text-5xl font-bold mb-6 leading-tight">Nginx日志配置完全指南</h1>
            <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto mb-8">掌握Nginx日志的配置艺术，洞悉服务器运行状态</p>
            <div class="flex flex-wrap justify-center gap-4">
                <a href="#intro" class="bg-white text-indigo-600 px-6 py-3 rounded-full font-medium hover:bg-opacity-90 transition duration-300">
                    <i class="fas fa-book-open mr-2"></i>开始阅读
                </a>
                <a href="#quick-start" class="bg-white bg-opacity-20 px-6 py-3 rounded-full font-medium hover:bg-opacity-30 transition duration-300">
                    <i class="fas fa-bolt mr-2"></i>快速配置
                </a>
            </div>
        </div>
    </section>

    <!-- Navigation -->
    <nav class="sticky top-0 bg-white shadow-sm z-10">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex justify-between items-center py-4">
                <a href="#" class="text-xl font-bold text-indigo-600">
                    <i class="fas fa-book mr-2"></i>技术小馆
                </a>
                <div class="hidden md:flex space-x-8">
                    <a href="#intro" class="nav-link pb-2">简介</a>
                    <a href="#access-log" class="nav-link pb-2">访问日志</a>
                    <a href="#error-log" class="nav-link pb-2">错误日志</a>
                    <a href="#custom-log" class="nav-link pb-2">自定义日志</a>
                    <a href="#best-practices" class="nav-link pb-2">最佳实践</a>
                </div>
                <button class="md:hidden text-gray-600">
                    <i class="fas fa-bars text-xl"></i>
                </button>
            </div>
        </div>
    </nav>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-12">
        <!-- Introduction -->
        <section id="intro" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                    <i class="fas fa-info-circle text-indigo-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold">为什么Nginx日志如此重要？</h2>
            </div>
            <div class="grid md:grid-cols-2 gap-8 mb-10">
                <div>
                    <p class="text-lg mb-6">Nginx日志是服务器运维和网站管理中的黄金数据源。它们记录了服务器接收到的每一个请求和发生的每一个错误，为我们提供了监控服务器状态、分析用户行为、排查问题和优化性能的关键信息。</p>
                    <div class="highlight-box mb-8">
                        <h3 class="text-xl font-semibold mb-3">日志的核心价值</h3>
                        <ul class="space-y-2">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-600 mt-1 mr-2"></i>
                                <span>实时监控服务器健康状况</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-600 mt-1 mr-2"></i>
                                <span>分析用户访问模式和流量来源</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-600 mt-1 mr-2"></i>
                                <span>快速定位和解决服务问题</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-600 mt-1 mr-2"></i>
                                <span>安全审计和异常行为检测</span>
                            </li>
                        </ul>
                    </div>
                </div>
                <div>
                    <div class="card bg-white p-6 h-full">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center mr-3">
                                <i class="fas fa-project-diagram text-purple-600"></i>
                            </div>
                            <h3 class="text-xl font-semibold">Nginx日志类型概览</h3>
                        </div>
                        <div class="mermaid">
                            graph TD
                                A[Nginx日志] --> B[访问日志]
                                A --> C[错误日志]
                                B --> D[记录客户端请求]
                                B --> E[可选格式自定义]
                                C --> F[记录服务器错误]
                                C --> G[可设置级别]
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Quick Start -->
        <section id="quick-start" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center mr-4">
                    <i class="fas fa-bolt text-blue-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold">快速配置指南</h2>
            </div>
            <div class="grid md:grid-cols-3 gap-6">
                <div class="card bg-white p-6">
                    <div class="text-blue-600 text-2xl mb-4">
                        <i class="fas fa-cog"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">基本访问日志</h3>
                    <p class="text-gray-600 mb-4">启用默认格式的访问日志记录</p>
                    <div class="code-block">
                        <button class="copy-btn" onclick="copyCode(this)">
                            <i class="far fa-copy"></i>
                        </button>
                        <pre><code>access_log /var/log/nginx/access.log;</code></pre>
                    </div>
                </div>
                <div class="card bg-white p-6">
                    <div class="text-green-600 text-2xl mb-4">
                        <i class="fas fa-exclamation-triangle"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">错误日志配置</h3>
                    <p class="text-gray-600 mb-4">设置错误日志路径和级别</p>
                    <div class="code-block">
                        <button class="copy-btn" onclick="copyCode(this)">
                            <i class="far fa-copy"></i>
                        </button>
                        <pre><code>error_log /var/log/nginx/error.log warn;</code></pre>
                    </div>
                </div>
                <div class="card bg-white p-6">
                    <div class="text-purple-600 text-2xl mb-4">
                        <i class="fas fa-sliders-h"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">条件日志记录</h3>
                    <p class="text-gray-600 mb-4">按需启用/禁用日志</p>
                    <div class="code-block">
                        <button class="copy-btn" onclick="copyCode(this)">
                            <i class="far fa-copy"></i>
                        </button>
                        <pre><code>location /private/ {
    access_log off;
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Access Log Section -->
        <section id="access-log" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-green-100 flex items-center justify-center mr-4">
                    <i class="fas fa-sign-in-alt text-green-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold">1. 配置访问日志</h2>
            </div>
            
            <div class="mb-8">
                <p class="text-lg mb-6">访问日志记录了所有对服务器的请求。我们可以通过 <code class="bg-gray-100 px-2 py-1 rounded">access_log</code> 指令来配置访问日志的路径和格式。</p>
                
                <div class="code-block mb-8">
                    <button class="copy-btn" onclick="copyCode(this)">
                        <i class="far fa-copy"></i>
                    </button>
                    <pre><code>http {
    # 定义日志格式
    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    # 配置访问日志文件路径及使用的日志格式
    access_log /var/log/nginx/access.log main;

    # 其他配置...
}</code></pre>
                </div>
                
                <div class="bg-white rounded-lg shadow-sm p-6 mb-8">
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-lightbulb text-yellow-500 mr-2"></i>
                        日志格式变量解析
                    </h3>
                    <div class="overflow-x-auto">
                        <table class="min-w-full divide-y divide-gray-200">
                            <thead class="bg-gray-50">
                                <tr>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">变量</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">说明</th>
                                </tr>
                            </thead>
                            <tbody class="bg-white divide-y divide-gray-200">
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">$remote_addr</td>
                                    <td class="px-6 py-4 text-sm text-gray-500">客户端IP地址</td>
                                </tr>
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">$remote_user</td>
                                    <td class="px-6 py-4 text-sm text-gray-500">HTTP认证用户名</td>
                                </tr>
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">$time_local</td>
                                    <td class="px-6 py-4 text-sm text-gray-500">访问时间和时区</td>
                                </tr>
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">$request</td>
                                    <td class="px-6 py-4 text-sm text-gray-500">请求方法和URI</td>
                                </tr>
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">$status</td>
                                    <td class="px-6 py-4 text-sm text-gray-500">HTTP状态码</td>
                                </tr>
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">$body_bytes_sent</td>
                                    <td class="px-6 py-4 text-sm text-gray-500">发送给客户端的字节数</td>
                                </tr>
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">$http_referer</td>
                                    <td class="px-6 py-4 text-sm text-gray-500">请求来源页</td>
                                </tr>
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">$http_user_agent</td>
                                    <td class="px-6 py-4 text-sm text-gray-500">用户代理(浏览器信息)</td>
                                </tr>
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">$http_x_forwarded_for</td>
                                    <td class="px-6 py-4 text-sm text-gray-500">代理服务器IP</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </section>

        <!-- Error Log Section -->
        <section id="error-log" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-red-100 flex items-center justify-center mr-4">
                    <i class="fas fa-exclamation-circle text-red-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold">2. 配置错误日志</h2>
            </div>
            
            <div class="mb-8">
                <p class="text-lg mb-6">错误日志记录了服务器的错误信息。我们可以通过 <code class="bg-gray-100 px-2 py-1 rounded">error_log</code> 指令来配置错误日志的路径和日志级别。</p>
                
                <div class="code-block mb-8">
                    <button class="copy-btn" onclick="copyCode(this)">
                        <i class="far fa-copy"></i>
                    </button>
                    <pre><code>http {
    # 配置错误日志文件路径及日志级别
    error_log /var/log/nginx/error.log warn;

    # 其他配置...
}</code></pre>
                </div>
                
                <div class="grid md:grid-cols-2 gap-8">
                    <div>
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-list-ol text-blue-500 mr-2"></i>
                            日志级别说明
                        </h3>
                        <ul class="space-y-3">
                            <li class="flex items-start">
                                <span class="bg-red-100 text-red-800 text-xs font-semibold px-2.5 py-0.5 rounded mr-2">emerg</span>
                                <span>紧急情况 - 系统不可用</span>
                            </li>
                            <li class="flex items-start">
                                <span class="bg-orange-100 text-orange-800 text-xs font-semibold px-2.5 py-0.5 rounded mr-2">alert</span>
                                <span>需要立即采取行动</span>
                            </li>
                            <li class="flex items-start">
                                <span class="bg-yellow-100 text-yellow-800 text-xs font-semibold px-2.5 py-0.5 rounded mr-2">crit</span>
                                <span>关键错误</span>
                            </li>
                            <li class="flex items-start">
                                <span class="bg-blue-100 text-blue-800 text-xs font-semibold px-2.5 py-0.5 rounded mr-2">error</span>
                                <span>错误</span>
                            </li>
                            <li class="flex items-start">
                                <span class="bg-indigo-100 text-indigo-800 text-xs font-semibold px-2.5 py-0.5 rounded mr-2">warn</span>
                                <span>警告</span>
                            </li>
                            <li class="flex items-start">
                                <span class="bg-gray-100 text-gray-800 text-xs font-semibold px-2.5 py-0.5 rounded mr-2">notice</span>
                                <span>普通但重要信息</span>
                            </li>
                            <li class="flex items-start">
                                <span class="bg-green-100 text-green-800 text-xs font-semibold px-2.5 py-0.5 rounded mr-2">info</span>
                                <span>一般信息</span>
                            </li>
                            <li class="flex items-start">
                                <span class="bg-purple-100 text-purple-800 text-xs font-semibold px-2.5 py-0.5 rounded mr-2">debug</span>
                                <span>调试信息</span>
                            </li>
                        </ul>
                    </div>
                    <div>
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-cogs text-purple-500 mr-2"></i>
                            错误日志应用场景
                        </h3>
                        <div class="space-y-4">
                            <div class="flex items-start">
                                <div class="flex-shrink-0 h-10 w-10 rounded-full bg-blue-50 flex items-center justify-center text-blue-600 mr-3">
                                    <i class="fas fa-search"></i>
                                </div>
                                <div>
                                    <h4 class="font-medium">问题排查</h4>
                                    <p class="text-sm text-gray-600">快速定位服务器错误原因，如配置错误、权限问题等</p>
                                </div>
                            </div>
                            <div class="flex items-start">
                                <div class="flex-shrink-0 h-10 w-10 rounded-full bg-purple-50 flex items-center justify-center text-purple-600 mr-3">
                                    <i class="fas fa-shield-alt"></i>
                                </div>
                                <div>
                                    <h4 class="font-medium">安全监控</h4>
                                    <p class="text-sm text-gray-600">发现异常访问和潜在攻击行为</p>
                                </div>
                            </div>
                            <div class="flex items-start">
                                <div class="flex-shrink-0 h-10 w-10 rounded-full bg-green-50 flex items-center justify-center text-green-600 mr-3">
                                    <i class="fas fa-chart-line"></i>
                                </div>
                                <div>
                                    <h4 class="font-medium">性能分析</h4>
                                    <p class="text-sm text-gray-600">识别性能瓶颈和资源问题</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Conditional Logging -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-yellow-100 flex items-center justify-center mr-4">
                    <i class="fas fa-filter text-yellow-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold">3. 设置日志记录的条件</h2>
            </div>
            
            <div class="mb-8">
                <p class="text-lg mb-6">Nginx 允许我们根据条件来启用或禁用日志记录。例如，在某些特定的 server 块或 location 块中，可以选择性地启用日志记录。</p>
                
                <div class="code-block mb-8">
                    <button class="copy-btn" onclick="copyCode(this)">
                        <i class="far fa-copy"></i>
                    </button>
                    <pre><code>server {
    listen 80;
    server_name example.com;

    # 仅为这个 server 块启用访问日志
    access_log /var/log/nginx/example.access.log main;

    location / {
        # 启用访问日志记录
        access_log /var/log/nginx/example.access.log main;
        # 其他配置...
    }

    # 禁用访问日志记录
    location /no-log/ {
        access_log off;
        # 其他配置...
    }
}</code></pre>
                </div>
                
                <div class="bg-blue-50 border-l-4 border-blue-400 p-4 mb-8">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-info-circle text-blue-500"></i>
                        </div>
                        <div class="ml-3">
                            <h3 class="text-sm font-medium text-blue-800">实用技巧</h3>
                            <div class="mt-2 text-sm text-blue-700">
                                <p>对于高流量网站，选择性禁用某些静态资源(如图片、CSS、JS)的日志记录可以显著减少日志文件大小，提高性能。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Custom Log Format -->
        <section id="custom-log" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-purple-100 flex items-center justify-center mr-4">
                    <i class="fas fa-sliders-h text-purple-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold">4. 自定义日志格式</h2>
            </div>
            
            <div class="mb-8">
                <p class="text-lg mb-6">Nginx 支持自定义日志格式。你可以根据需要定义不同的日志格式，并在 <code class="bg-gray-100 px-2 py-1 rounded">access_log</code> 指令中使用它们。</p>
                
                <div class="code-block mb-8">
                    <button class="copy-btn" onclick="copyCode(this)">
                        <i class="far fa-copy"></i>
                    </button>
                    <pre><code>http {
    # 自定义日志格式
    log_format custom '$remote_addr - $remote_user [$time_local] "$request" '
                       '$status $body_bytes_sent "$http_referer" '
                       '"$http_user_agent"';

    access_log /var/log/nginx/custom_access.log custom;
    # 其他配置...
}</code></pre>
                </div>
                
                <div class="grid md:grid-cols-2 gap-8">
                    <div class="card bg-white p-6">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-lightbulb text-yellow-500 mr-2"></i>
                            常用自定义格式示例
                        </h3>
                        <div class="space-y-4">
                            <div>
                                <h4 class="font-medium mb-2">JSON格式日志</h4>
                                <div class="code-block">
                                    <button class="copy-btn" onclick="copyCode(this)">
                                        <i class="far fa-copy"></i>
                                    </button>
                                    <pre><code>log_format json_combined escape=json
    '{"time_local":"$time_local",'
    '"remote_addr":"$remote_addr",'
    '"request":"$request",'
    '"status": "$status",'
    '"body_bytes_sent":"$body_bytes_sent",'
    '"http_referer":"$http_referer",'
    '"http_user_agent":"$http_user_agent"}';</code></pre>
                                </div>
                            </div>
                            <div>
                                <h4 class="font-medium mb-2">性能监控格式</h4>
                                <div class="code-block">
                                    <button class="copy-btn" onclick="copyCode(this)">
                                        <i class="far fa-copy"></i>
                                    </button>
                                    <pre><code>log_format perf '$remote_addr - [$time_local] "$request" '
                   '$status $body_bytes_sent $request_time $upstream_response_time';</code></pre>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="card bg-white p-6">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-cog text-blue-500 mr-2"></i>
                            高级日志配置
                        </h3>
                        <ul class="space-y-3">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <div>
                                    <span class="font-medium">缓冲日志写入</span>
                                    <p class="text-sm text-gray-600">使用<code class="bg-gray-100 px-1 rounded">buffer=size</code>参数优化高流量场景下的日志写入性能</p>
                                </div>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <div>
                                    <span class="font-medium">日志轮转</span>
                                    <p class="text-sm text-gray-600">结合logrotate工具定期轮转日志文件，防止单个文件过大</p>
                                </div>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <div>
                                    <span class="font-medium">条件日志</span>
                                    <p class="text-sm text-gray-600">使用<code class="bg-gray-100 px-1 rounded">if</code>条件实现更精细的日志记录控制</p>
                                </div>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <div>
                                    <span class="font-medium">多日志文件</span>
                                    <p class="text-sm text-gray-600">不同虚拟主机或URL路径使用不同的日志文件</p>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <!-- Best Practices -->
        <section id="best-practices" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                    <i class="fas fa-star text-indigo-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold">Nginx日志最佳实践</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="card bg-white p-6">
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 rounded-full bg-blue-100 flex items-center justify-center mr-3">
                            <i class="fas fa-shield-alt text-blue-600"></i>
                        </div>
                        <h3 class="text-xl font-semibold">安全与隐私考虑</h3>
                    </div>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>敏感信息(如密码、token)不应记录在日志中</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>遵守GDPR等隐私法规，考虑匿名化用户数据</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>限制日志文件权限，防止未授权访问</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>定期审查日志内容，及时发现安全问题</span>
                        </li>
                    </ul>
                </div>
                <div class="card bg-white p-6">
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 rounded-full bg-green-100 flex items-center justify-center mr-3">
                            <i class="fas fa-tachometer-alt text-green-600"></i>
                        </div>
                        <h3 class="text-xl font-semibold">性能优化建议</h3>
                    </div>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>高流量场景下使用缓冲日志写入(buffer参数)</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>静态资源请求考虑禁用日志记录</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>定期轮转和压缩历史日志文件</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>避免过于详细的日志格式影响性能</span>
                        </li>
                    </ul>
                </div>
            </div>
            
            <div class="mt-8">
                <div class="card bg-white p-6">
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center mr-3">
                            <i class="fas fa-tools text-purple-600"></i>
                        </div>
                        <h3 class="text-xl font-semibold">日志分析与可视化工具</h3>
                    </div>
                    <div class="grid md:grid-cols-3 gap-6">
                        <div class="border rounded-lg p-4">
                            <div class="text-blue-500 text-2xl mb-2">
                                <i class="fab fa-searchengin"></i>
                            </div>
                            <h4 class="font-semibold mb-1">GoAccess</h4>
                            <p class="text-sm text-gray-600">实时Web日志分析工具，提供终端和HTML报告</p>
                        </div>
                        <div class="border rounded-lg p-4">
                            <div class="text-yellow-500 text-2xl mb-2">
                                <i class="fas fa-chart-bar"></i>
                            </div>
                            <h4 class="font-semibold mb-1">ELK Stack</h4>
                            <p class="text-sm text-gray-600">Elasticsearch + Logstash + Kibana日志分析平台</p>
                        </div>
                        <div class="border rounded-lg p-4">
                            <div class="text-green-500 text-2xl mb-2">
                                <i class="fas fa-cloud"></i>
                            </div>
                            <h4 class="font-semibold mb-1">Grafana Loki</h4>
                            <p class="text-sm text-gray-600">轻量级日志聚合系统，专为云原生环境设计</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Conclusion -->
        <section class="mb-20">
            <div class="bg-indigo-50 rounded-xl p-8 md:p-10 text-center">
                <div class="max-w-3xl mx-auto">
                    <div class="w-16 h-16 bg-indigo-100 rounded-full flex items-center justify-center mx-auto mb-6">
                        <i class="fas fa-check-circle text-indigo-600 text-2xl"></i>
                    </div>
                    <h2 class="text-2xl md:text-3xl font-bold mb-4">掌握Nginx日志配置</h2>
                    <p class="text-lg mb-6">通过合理配置Nginx日志，您将能够更好地监控服务器状态、分析用户行为、排查问题和优化性能。记住定期检查日志、轮转日志文件，并考虑使用日志分析工具来获得更多洞察。</p>
                    <div class="flex flex-wrap justify-center gap-4">
                        <a href="#quick-start" class="bg-indigo-600 text-white px-6 py-3 rounded-full font-medium hover:bg-indigo-700 transition duration-300">
                            <i class="fas fa-arrow-up mr-2"></i>返回快速配置
                        </a>
                        <a href="http://www.yuque.com/jtostring" class="bg-white text-indigo-600 px-6 py-3 rounded-full font-medium hover:bg-gray-100 transition duration-300">
                            <i class="fas fa-book mr-2"></i>更多技术文章
                        </a>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-10">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-bold text-white">
                        <i class="fas fa-book mr-2"></i>技术小馆
                    </h3>
                    <p class="text-sm">专业的技术文章与教程</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-indigo-400 hover:text-indigo-300 transition duration-300">
                        <i class="fas fa-external-link-alt mr-1"></i>访问技术小馆
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-sm text-center text-gray-500">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        // 初始化Mermaid图表
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            fontFamily: 'Noto Sans SC, sans-serif'
        });

        // 复制代码功能
        function copyCode(button) {
            const codeBlock = button.parentElement;
            const code = codeBlock.querySelector('pre').innerText;
            navigator.clipboard.writeText(code).then(() => {
                const originalIcon = button.innerHTML;
                button.innerHTML = '<i class="fas fa-check"></i>';
                setTimeout(() => {
                    button.innerHTML = originalIcon;
                }, 2000);
            });
        }

        // 平滑滚动
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>